﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.DA;
using Com.BU;

namespace ThermalEquipmentDesign.Model.Condenser.HorizontalPipeR12
{
    public class HorizontalPipeR12 : ObservableObject
    {
        // Declare fields for inputting
        #region Feild Input
        private double dbcoldProductivity;
        private double dbboilingTemp;
        private double dbcoolingTemp;
        private double dbdegreeIncreaseTemp;
        private double dbdiffTemp;
        private double dbinterDiameter = 0.0132;
        private double dbexterDiameter = 0.021;
        private double dbbaseDiameter = 0.0165;
        private double dbfinPitch = 0.002;
        private double dbexterArea = 0.149;
        private double dbinterArea = 0.0415;
        private double dbwaterSpeed = 1.9;
        private double dbthermalResistance = 2.6 * Math.Pow(10, -4);
        private double dbaverageWaterThermalCapacity = 4.18;
        private double dbdensity = 993.2;
        private double dbkinematicViscosity = 0.693 * Math.Pow(10, -6);
        private double dbprandtlCoefficient = 4.64;
        private double dbheatConductivityCoefficient = 0.629;
        #endregion

        // Create properties for fields
        #region Properties Input
        public double dbColdProductivity
        {
            get { return dbcoldProductivity; }
            set
            {
                if (value != dbcoldProductivity)
                {
                    dbcoldProductivity = value;
                    OnPropertyChanged("dbColdProductivity");
                }
            }
        }

        public double dbBoilingTemp
        {
            get { return dbboilingTemp; }
            set { dbboilingTemp = value; }
        }

        public double dbCoolingTemp
        {
            get { return dbcoolingTemp; }
            set
            {
                if (value != dbcoolingTemp)
                {
                    dbcoolingTemp = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbCoolingTemp");
                }
            }
        }

        public double dbDegreeIncreaseTemp
        {
            get { return dbdegreeIncreaseTemp; }
            set
            {
                if (value != dbdegreeIncreaseTemp)
                {
                    dbdegreeIncreaseTemp = value;
                    SetAverageTemp();
                    OnPropertyChanged("dbDegreeIncreaseTemp");
                }
            }
        }

        public double dbDiffTemp
        {
            get { return dbdiffTemp; }
            set { dbdiffTemp = value; }
        }

        public double dbInterDiameter
        {
            get { return dbinterDiameter; }
            set { dbinterDiameter = value; }
        }

        public double dbExterDiameter
        {
            get { return dbexterDiameter; }
            set { dbexterDiameter = value; }
        }

        public double dbBaseDiameter
        {
            get { return dbbaseDiameter; }
            set { dbbaseDiameter = value; }
        }

        public double dbFinPitch
        {
            get { return dbfinPitch; }
            set { dbfinPitch = value; }
        }

        public double dbExterArea
        {
            get { return dbexterArea; }
            set { dbexterArea = value; }
        }

        public double dbInterArea
        {
            get { return dbinterArea; }
            set { dbinterArea = value; }
        }

        public double dbWaterSpeed
        {
            get { return dbwaterSpeed; }
            set { dbwaterSpeed = value; }
        }

        public double dbThermalResistance
        {
            get { return dbthermalResistance; }
            set { dbthermalResistance = value; }
        }

        public double dbAverageWaterThermalCapacity
        {
            get { return dbaverageWaterThermalCapacity; }
            set { dbaverageWaterThermalCapacity = value; }
        }

        public double dbDensity
        {
            get { return dbdensity; }
            set { dbdensity = value; }
        }

        public double dbKinematicViscosity
        {
            get { return dbkinematicViscosity; }
            set { dbkinematicViscosity = value; }
        }

        public double dbPrandtlCoefficient
        {
            get { return dbprandtlCoefficient; }
            set { dbprandtlCoefficient = value; }
        }

        public double dbHeatConductivityCoefficient
        {
            get { return dbheatConductivityCoefficient; }
            set { dbheatConductivityCoefficient = value; }
        }
        #endregion

        /// <summary>
        /// Change value foe properties that realted with average temperature
        /// </summary>
        private void SetAverageTemp()
        {
            double dbaverageTemp = (2 * dbcoolingTemp + dbdegreeIncreaseTemp) * 0.5;
            tb_water_coefficients watercoefficients = LibraryManagerInCom.WaterCoefficientsList.SingleOrDefault(w => w.Temperature == dbaverageTemp);
            if (watercoefficients != null)
            {
                dbaverageWaterThermalCapacity = (double)watercoefficients.HeatSpecific;
                dbdensity = (double)watercoefficients.Density01;
                dbkinematicViscosity = (double)watercoefficients.KinematicViscosity;
                dbprandtlCoefficient = (double)watercoefficients.Prandtl_Coefficient;
                dbheatConductivityCoefficient = (double)watercoefficients.HeatConductivity;
                OnPropertyChanged("dbAverageWaterThermalCapacity");
                OnPropertyChanged("dbDensity");
                OnPropertyChanged("dbKinematicViscosity");
                OnPropertyChanged("dbPrandtlCoefficient");
                OnPropertyChanged("dbHeatConductivityCoefficient");
            }
        }
    }
}
